package com.shuai.service.impl;

import com.shuai.constant.LoginTypeConstant;
import com.shuai.context.BaseContext;
import com.shuai.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaseContentService {

    @Autowired
    private UserMapper userMapper;

    //获取基础内容
    public  Long getEnterpriseId(){
        Long enterpriseId;
        //判断登录类型
        Integer loginType = BaseContext.getCurrentLoginInfo().getLoginType();
        if (loginType == LoginTypeConstant.ENTERPRISE_LOGIN){
            //当前为企业登录
            enterpriseId = BaseContext.getCurrentLoginInfo().getId();
        }else {
            //当前为用户登录
            Long userId = BaseContext.getCurrentLoginInfo().getId();
            enterpriseId = userMapper.getById(userId).getEnterpriseId();
        }
        return enterpriseId;
    }

    public static Long getUserId(){
        return BaseContext.getCurrentLoginInfo().getId();
    }
}
